home *** CD-ROM | disk | FTP | other *** search
/ Champak 50 / Volume 50 - JOGO DISK .iso / Games / moonstonemadness.swf / scripts / __Packages / LevelEditor.as < prev    next >
Encoding:
Text File  |  2007-09-27  |  15.3 KB  |  414 lines

  1. class LevelEditor
  2. {
  3.    var mcRef;
  4.    var aPlayObjects;
  5.    var aRotateObjects;
  6.    var aRotatingObjects;
  7.    var bMoving;
  8.    var oLevel;
  9.    var oPanMachine;
  10.    var bBoxUsingFeather;
  11.    var nCurrentBoxNumber;
  12.    static var oCtrl;
  13.    static var LETTERS = ["A","B","C","D","E","F","G","H","I","J"];
  14.    static var PANELS = ["Amb_LE_mcGamePanel01","Amb_LE_mcGamePanel02","Amb_LE_mcGamePanel03","Amb_LE_mcGamePanel04","Amb_LE_mcGamePanel05","Amb_LE_mcGamePanel06","Amb_LE_mcGamePanel07","Amb_LE_mcGamePanel08","Amb_LE_mcGamePanel09","Amb_LE_mcGamePanel10"];
  15.    static var SUFFIX_FEATHER = "_F";
  16.    static var SUFFIX_MOONSTONES = "_MS";
  17.    static var PANELS_QTY = 25;
  18.    static var MIN_SECONDS = 180;
  19.    static var MAX_MINUTES = 15;
  20.    static var MIN_MOONSTONES = 5;
  21.    static var MAX_MOONSTONES = 100;
  22.    function LevelEditor(__mcRef, __bEditLevel, __oLevelToEdit, __nNewLevelTargetRow)
  23.    {
  24.       this.mcRef = __mcRef;
  25.       LevelEditor.oCtrl = this;
  26.       this.aPlayObjects = new Array();
  27.       this.aRotateObjects = new Array();
  28.       this.aRotatingObjects = new Array();
  29.       this.bMoving = false;
  30.       if(__bEditLevel)
  31.       {
  32.          this.oLevel = __oLevelToEdit;
  33.       }
  34.       else
  35.       {
  36.          this.oLevel = new BaseLevelData();
  37.          this.oLevel.LevelNumber = __nNewLevelTargetRow;
  38.          this.oLevel.LevelType = BaseLevelData.LEVEL_TYPE_USER;
  39.          this.oLevel.sPanelBg1 = "Amb_LE_mcBgPanel1";
  40.          this.oLevel.aPanelBg2.push("Amb_LE_mcBgPanel2_A");
  41.          this.oLevel.aPanelBg2.push("Amb_LE_mcBgPanel2_B");
  42.          this.oLevel.aPanelBg2.push("Amb_LE_mcBgPanel2_C");
  43.          this.oLevel.RequiredMS = 25;
  44.          this.oLevel.TimeAllowed = 300000;
  45.          this.oLevel.nFloorHeight = 345;
  46.          this.oLevel.sPanelStart = "Amb_LE_mcGamePanel_Start";
  47.          this.oLevel.sPanelEnd = "Amb_LE_mcGamePanel_End";
  48.          var _loc3_ = 1;
  49.          while(_loc3_ <= LevelEditor.PANELS_QTY)
  50.          {
  51.             var _loc4_ = LevelEditor.PANELS[Library.Utils.MoreMath.getRandomRange(0,LevelEditor.PANELS.length - 1)];
  52.             var _loc2_ = undefined;
  53.             if(Math.random() < 0.5)
  54.             {
  55.                _loc2_ = LevelEditor.SUFFIX_FEATHER;
  56.             }
  57.             else
  58.             {
  59.                _loc2_ = LevelEditor.SUFFIX_MOONSTONES;
  60.             }
  61.             var _loc5_ = _loc4_ + _loc2_;
  62.             this.oLevel.Panels.push(_loc5_);
  63.             _loc3_ = _loc3_ + 1;
  64.          }
  65.          Game.Instance.Status.doAddUserLevel(this.oLevel);
  66.       }
  67.       this.doInit();
  68.       this.doSetUpMachine();
  69.       Main.Instance.doAddListener(this);
  70.    }
  71.    static function get Instance()
  72.    {
  73.       return LevelEditor.oCtrl;
  74.    }
  75.    function doHelpPage(__nPage)
  76.    {
  77.       this.mcRef.mcHelp.gotoAndStop(__nPage);
  78.    }
  79.    function doShowHelp()
  80.    {
  81.       this.mcRef.mcHelp._visible = true;
  82.       this.doHelpPage(1);
  83.    }
  84.    function doHideHelp()
  85.    {
  86.       this.mcRef.mcHelp._visible = false;
  87.    }
  88.    function onMoveStartFor(__mcHit)
  89.    {
  90.       for(var _loc3_ in this.aPlayObjects)
  91.       {
  92.          if(this.aPlayObjects[_loc3_].hitTest(__mcHit))
  93.          {
  94.             this.aPlayObjects[_loc3_].play();
  95.          }
  96.       }
  97.       for(_loc3_ in this.aRotateObjects)
  98.       {
  99.          if(this.aRotateObjects[_loc3_].hitTest(__mcHit))
  100.          {
  101.             this.aRotatingObjects.push(this.aRotateObjects[_loc3_]);
  102.          }
  103.       }
  104.       this.bMoving = true;
  105.    }
  106.    function onMoveStop()
  107.    {
  108.       for(var _loc2_ in this.aPlayObjects)
  109.       {
  110.          this.aPlayObjects[_loc2_].stop();
  111.       }
  112.       this.aRotatingObjects = new Array();
  113.       this.bMoving = false;
  114.    }
  115.    function doAddPlayObject(__mcObj)
  116.    {
  117.       this.aPlayObjects.push(__mcObj);
  118.       __mcObj.stop();
  119.    }
  120.    function doAddRotateObject(__mcObj)
  121.    {
  122.       this.aRotateObjects.push(__mcObj);
  123.    }
  124.    function doEnterFrame()
  125.    {
  126.       if(this.bMoving)
  127.       {
  128.          for(var _loc2_ in this.aRotatingObjects)
  129.          {
  130.             this.aRotatingObjects[_loc2_]._rotation += 10;
  131.          }
  132.       }
  133.    }
  134.    function doBuzzerSound()
  135.    {
  136.       Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"Buzzer.mp3",100,1,true);
  137.    }
  138.    function doSecondsChange(__nChange)
  139.    {
  140.       this.oLevel.TimeAllowed += __nChange * 1000;
  141.       if(this.oLevel.TimeAllowed > LevelEditor.MAX_MINUTES * 60 * 1000)
  142.       {
  143.          this.oLevel.TimeAllowed = LevelEditor.MAX_MINUTES * 60 * 1000;
  144.          this.doBuzzerSound();
  145.       }
  146.       else if(this.oLevel.TimeAllowed < LevelEditor.MIN_SECONDS * 1000)
  147.       {
  148.          this.oLevel.TimeAllowed = LevelEditor.MIN_SECONDS * 1000;
  149.          this.doBuzzerSound();
  150.       }
  151.       this.oLevel.Completed = false;
  152.       this.doUpdateTimeNumber();
  153.    }
  154.    function doMinutesChange(__nChange)
  155.    {
  156.       this.oLevel.TimeAllowed += __nChange * 60 * 1000;
  157.       if(this.oLevel.TimeAllowed > LevelEditor.MAX_MINUTES * 60 * 1000)
  158.       {
  159.          this.oLevel.TimeAllowed = LevelEditor.MAX_MINUTES * 60 * 1000;
  160.          this.doBuzzerSound();
  161.       }
  162.       else if(this.oLevel.TimeAllowed < LevelEditor.MIN_SECONDS * 1000)
  163.       {
  164.          this.oLevel.TimeAllowed = LevelEditor.MIN_SECONDS * 1000;
  165.          this.doBuzzerSound();
  166.       }
  167.       this.oLevel.Completed = false;
  168.       this.doUpdateTimeNumber();
  169.    }
  170.    function doMoonStonesChange(__nChange)
  171.    {
  172.       this.oLevel.RequiredMS += __nChange;
  173.       if(this.oLevel.RequiredMS > LevelEditor.MAX_MOONSTONES)
  174.       {
  175.          this.oLevel.RequiredMS = LevelEditor.MAX_MOONSTONES;
  176.          this.doBuzzerSound();
  177.       }
  178.       else if(this.oLevel.RequiredMS < LevelEditor.MIN_MOONSTONES)
  179.       {
  180.          this.oLevel.RequiredMS = LevelEditor.MIN_MOONSTONES;
  181.          this.doBuzzerSound();
  182.       }
  183.       this.oLevel.Completed = false;
  184.       this.doUpdateMoonStonesNumber();
  185.    }
  186.    function doTestLevel()
  187.    {
  188.       this.oLevel.doSave();
  189.       Game.Instance.doTestLevel(this.oLevel);
  190.    }
  191.    function doExitEditor()
  192.    {
  193.       this.oLevel.doSave();
  194.       Game.Instance.doExitEditor();
  195.    }
  196.    function onLevelNameChange()
  197.    {
  198.       this.oLevel.LevelName = this.mcRef.txtLevelName.text;
  199.    }
  200.    function onToggleFeather()
  201.    {
  202.       if(this.oPanMachine.CurrentState == "Idle")
  203.       {
  204.          if(this.oPanMachine.CenterMachine.CurrentState == "Idle")
  205.          {
  206.             this.bBoxUsingFeather = !this.bBoxUsingFeather;
  207.             var _loc3_ = this.getNumberForPanel(this.oLevel.Panels[this.nCurrentBoxNumber - 1]);
  208.             var _loc2_ = LevelEditor.SUFFIX_MOONSTONES;
  209.             if(this.bBoxUsingFeather)
  210.             {
  211.                _loc2_ = LevelEditor.SUFFIX_FEATHER;
  212.             }
  213.             this.oLevel.Panels[this.nCurrentBoxNumber - 1] = LevelEditor.PANELS[_loc3_] + _loc2_;
  214.             this.oLevel.Completed = false;
  215.             this.doUpdateFeatherCheck();
  216.          }
  217.       }
  218.    }
  219.    function onScrollPanels(__nMove)
  220.    {
  221.       if(this.oPanMachine.CurrentState == "Idle")
  222.       {
  223.          if(this.oPanMachine.CenterMachine.CurrentState == "Idle")
  224.          {
  225.             var _loc3_ = this.getNumberForPanel(this.oLevel.Panels[this.nCurrentBoxNumber - 1]);
  226.             var _loc2_ = _loc3_ + __nMove;
  227.             if(_loc2_ < 0)
  228.             {
  229.                _loc2_ = LevelEditor.PANELS.length - 1;
  230.             }
  231.             if(_loc2_ > LevelEditor.PANELS.length - 1)
  232.             {
  233.                _loc2_ = 0;
  234.             }
  235.             this.oLevel.Panels[this.nCurrentBoxNumber - 1] = LevelEditor.PANELS[_loc2_] + this.getCurrentSuffix();
  236.             if(__nMove == 1)
  237.             {
  238.                this.oPanMachine.CenterMachine.doScrollUp();
  239.                this.onMoveStartFor(this.mcRef.mcZone2);
  240.                Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"EditorMove1.mp3",100,1,true);
  241.             }
  242.             else
  243.             {
  244.                this.oPanMachine.CenterMachine.doScrollDown();
  245.                this.onMoveStartFor(this.mcRef.mcZone1);
  246.                Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"EditorMove1.mp3",100,1,true);
  247.             }
  248.             this.oLevel.Completed = false;
  249.          }
  250.       }
  251.    }
  252.    function onScrollSide(__nMove)
  253.    {
  254.       if(this.oPanMachine.CurrentState == "Idle")
  255.       {
  256.          var _loc2_ = this.nCurrentBoxNumber + __nMove;
  257.          if(_loc2_ < 1)
  258.          {
  259.             _loc2_ = LevelEditor.PANELS_QTY;
  260.          }
  261.          if(_loc2_ > LevelEditor.PANELS_QTY)
  262.          {
  263.             _loc2_ = 1;
  264.          }
  265.          this.nCurrentBoxNumber = _loc2_;
  266.          this.doUpdateFeatherCheck();
  267.          if(__nMove == 1)
  268.          {
  269.             this.oPanMachine.doScrollToLeft();
  270.             this.onMoveStartFor(this.mcRef.mcZone4);
  271.             Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"EditorMove2.mp3",100,1,true);
  272.          }
  273.          else
  274.          {
  275.             this.oPanMachine.doScrollToRight();
  276.             this.onMoveStartFor(this.mcRef.mcZone3);
  277.             Library.Sound.SoundManager.doPlaySoundInCat(Main.SOUND_CAT_SOUND,"EditorMove2.mp3",100,1,true);
  278.          }
  279.       }
  280.       this.mcRef.txtQtyCur.text = Library.Utils.Tools.getFormatedNumber(this.nCurrentBoxNumber,2);
  281.       this.mcRef.txtQtyAll.text = Library.Utils.Tools.getFormatedNumber(LevelEditor.PANELS_QTY,2);
  282.    }
  283.    function getPanelLinkage(__nPanelNumber)
  284.    {
  285.       return LevelEditor.PANELS[__nPanelNumber];
  286.    }
  287.    function getLinkageFor(__nPanelNumber)
  288.    {
  289.       return this.oLevel.Panels[__nPanelNumber - 1];
  290.    }
  291.    function getCurrentSuffix()
  292.    {
  293.       var _loc2_ = this.oLevel.Panels[this.nCurrentBoxNumber - 1];
  294.       var _loc4_ = undefined;
  295.       var _loc3_ = _loc2_.lastIndexOf("_");
  296.       _loc4_ = _loc2_.substring(_loc3_);
  297.       return _loc4_;
  298.    }
  299.    function getNumberForPanel(__sExtendedName)
  300.    {
  301.       var _loc2_ = undefined;
  302.       var _loc1_ = 0;
  303.       while(_loc1_ <= LevelEditor.PANELS.length - 1)
  304.       {
  305.          if(__sExtendedName.indexOf(LevelEditor.PANELS[_loc1_]) != -1)
  306.          {
  307.             _loc2_ = _loc1_;
  308.             _loc1_ = LevelEditor.PANELS.length;
  309.          }
  310.          _loc1_ = _loc1_ + 1;
  311.       }
  312.       return _loc2_;
  313.    }
  314.    function doRefreshVisual()
  315.    {
  316.       this.oPanMachine.doRefreshVisual();
  317.    }
  318.    function doDestroy()
  319.    {
  320.    }
  321.    function get CurrentPanelNumber()
  322.    {
  323.       return this.nCurrentBoxNumber;
  324.    }
  325.    function doSetUpMachine()
  326.    {
  327.       this.oPanMachine = new EditorPanMachine(this.mcRef.mcMachine);
  328.       this.mcRef.btnHelp.onRelease = Library.Utils.Delegate.create(this,this.doShowHelp);
  329.       this.mcRef.btnLeft.onRelease = Library.Utils.Delegate.create(this,this.onScrollSide,-1);
  330.       this.mcRef.btnRight.onRelease = Library.Utils.Delegate.create(this,this.onScrollSide,1);
  331.       this.mcRef.btnUp.onRelease = Library.Utils.Delegate.create(this,this.onScrollPanels,-1);
  332.       this.mcRef.btnDown.onRelease = Library.Utils.Delegate.create(this,this.onScrollPanels,1);
  333.       this.doUpdateFeatherCheck();
  334.       this.mcRef.mcHelp._visible = false;
  335.       this.mcRef.mcHelp.stop();
  336.       this.mcRef.mcHelp.btnExit.onRelease = Library.Utils.Delegate.create(this,this.doHideHelp);
  337.       this.mcRef.mcHelp.btnBlock.useHandCursor = false;
  338.       this.mcRef.mcHelp.btnHelp1.onRollOver = Library.Utils.Delegate.create(this,this.doHelpPage,4);
  339.       this.mcRef.mcHelp.btnHelp2.onRollOver = Library.Utils.Delegate.create(this,this.doHelpPage,9);
  340.       this.mcRef.mcHelp.btnHelp3.onRollOver = Library.Utils.Delegate.create(this,this.doHelpPage,3);
  341.       this.mcRef.mcHelp.btnHelp4.onRollOver = Library.Utils.Delegate.create(this,this.doHelpPage,8);
  342.       this.mcRef.mcHelp.btnHelp5.onRollOver = Library.Utils.Delegate.create(this,this.doHelpPage,7);
  343.       this.mcRef.mcHelp.btnHelp6.onRollOver = Library.Utils.Delegate.create(this,this.doHelpPage,5);
  344.       this.mcRef.mcHelp.btnHelp7.onRollOver = Library.Utils.Delegate.create(this,this.doHelpPage,2);
  345.       this.mcRef.mcHelp.btnHelp8.onRollOver = Library.Utils.Delegate.create(this,this.doHelpPage,6);
  346.       this.mcRef.mcHelp.btnHelp1.onRollOut = Library.Utils.Delegate.create(this,this.doHelpPage,1);
  347.       this.mcRef.mcHelp.btnHelp2.onRollOut = Library.Utils.Delegate.create(this,this.doHelpPage,1);
  348.       this.mcRef.mcHelp.btnHelp3.onRollOut = Library.Utils.Delegate.create(this,this.doHelpPage,1);
  349.       this.mcRef.mcHelp.btnHelp4.onRollOut = Library.Utils.Delegate.create(this,this.doHelpPage,1);
  350.       this.mcRef.mcHelp.btnHelp5.onRollOut = Library.Utils.Delegate.create(this,this.doHelpPage,1);
  351.       this.mcRef.mcHelp.btnHelp6.onRollOut = Library.Utils.Delegate.create(this,this.doHelpPage,1);
  352.       this.mcRef.mcHelp.btnHelp7.onRollOut = Library.Utils.Delegate.create(this,this.doHelpPage,1);
  353.       this.mcRef.mcHelp.btnHelp8.onRollOut = Library.Utils.Delegate.create(this,this.doHelpPage,1);
  354.    }
  355.    function doInit()
  356.    {
  357.       this.nCurrentBoxNumber = 1;
  358.       this.mcRef.txtQtyCur.text = Library.Utils.Tools.getFormatedNumber(this.nCurrentBoxNumber,2);
  359.       this.mcRef.txtQtyAll.text = Library.Utils.Tools.getFormatedNumber(LevelEditor.PANELS_QTY,2);
  360.       this.mcRef.btnQuitEditor.onRelease = Library.Utils.Delegate.create(this,this.doExitEditor);
  361.       this.mcRef.btnTest.onRelease = Library.Utils.Delegate.create(this,this.doTestLevel);
  362.       this.mcRef.txtLevelName.text = this.oLevel.LevelName;
  363.       this.mcRef.txtLevelName.restrict = "a-z A-Z 0-9 _";
  364.       this.mcRef.txtLevelName.onChanged = Library.Utils.Delegate.create(this,this.onLevelNameChange);
  365.       this.doUpdateFeatherCheck();
  366.       this.doUpdateMoonStonesNumber();
  367.       this.doUpdateTimeNumber();
  368.    }
  369.    function doUpdateFeatherCheck()
  370.    {
  371.       var _loc2_ = undefined;
  372.       if(this.getCurrentSuffix() == LevelEditor.SUFFIX_FEATHER)
  373.       {
  374.          this.bBoxUsingFeather = true;
  375.          _loc2_ = "On";
  376.       }
  377.       else
  378.       {
  379.          this.bBoxUsingFeather = false;
  380.          _loc2_ = "Off";
  381.       }
  382.       this.mcRef.mcFeatherCheckBox.gotoAndStop(_loc2_);
  383.       this.mcRef.mcFeatherCheckBox.btnToggle.onRelease = Library.Utils.Delegate.create(this,this.onToggleFeather);
  384.       this.doRefreshVisual();
  385.    }
  386.    function doUpdateMoonStonesNumber()
  387.    {
  388.       this.mcRef.mcMoonStones.txtNumber.text = this.oLevel.RequiredMS;
  389.       this.mcRef.mcMoonStones.btnHaut.onRelease = Library.Utils.Delegate.create(this,this.doMoonStonesChange,5);
  390.       this.mcRef.mcMoonStones.btnBas.onRelease = Library.Utils.Delegate.create(this,this.doMoonStonesChange,-5);
  391.    }
  392.    function doUpdateTimeNumber()
  393.    {
  394.       var _loc2_ = this.oLevel.TimeAllowed / 1000 / 60;
  395.       _loc2_ = Math.floor(_loc2_);
  396.       var _loc3_ = undefined;
  397.       if(_loc2_ > 0)
  398.       {
  399.          _loc3_ = this.oLevel.TimeAllowed / 1000 % (_loc2_ * 60);
  400.       }
  401.       else
  402.       {
  403.          _loc3_ = this.oLevel.TimeAllowed / 1000;
  404.       }
  405.       _loc3_ = Math.floor(_loc3_);
  406.       this.mcRef.mcMinutes.txtNumber.text = _loc2_;
  407.       this.mcRef.mcSeconds.txtNumber.text = Library.Utils.Tools.getFormatedNumber(_loc3_,2);
  408.       this.mcRef.mcMinutes.btnHaut.onRelease = Library.Utils.Delegate.create(this,this.doMinutesChange,1);
  409.       this.mcRef.mcMinutes.btnBas.onRelease = Library.Utils.Delegate.create(this,this.doMinutesChange,-1);
  410.       this.mcRef.mcSeconds.btnHaut.onRelease = Library.Utils.Delegate.create(this,this.doSecondsChange,5);
  411.       this.mcRef.mcSeconds.btnBas.onRelease = Library.Utils.Delegate.create(this,this.doSecondsChange,-5);
  412.    }
  413. }
  414.